using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerBlackholeState : PlayerState
{
    private float flyTime = .4f;
    private bool skillUsed;

    private float defaultGravity;

    public PlayerBlackholeState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName) : base(_player, _stateMachine, _animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();
        defaultGravity = rb.gravityScale;//记录默认重力
        skillUsed = false;// 没有使用技能
        stateTimer = flyTime;// 飞起时间
        rb.gravityScale = 0;// 无重力
    }

    public override void Exit()
    {
        base.Exit();
        // 从黑洞技能攻击完后调用退出状态
        rb.gravityScale = defaultGravity;// 恢复重力
        player.fx.MakeTransprent(false);// 恢复角色
    }

    public override void Update()
    {
        base.Update();
        if (stateTimer > 0)
        {
            rb.velocity = new Vector2(0, 15);
        }
        if (stateTimer <= 0)
        {
            rb.velocity = new Vector2(0, -.1f);
            if (!skillUsed)
            {
                if (player.skill.blackhole.CanUseSkill())//飞到顶点后判断能否用技能
                    skillUsed = true;
            }
        }
        if (player.skill.blackhole.SkillCompleted())
        {
            stateMachine.ChangeState(player.airState);
        }
    }

}
